package com.yuque.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.bcel.internal.generic.IUSHR;
import com.yuque.pojo.category;
import com.yuque.service.CategoryService;
import com.yuque.util.QueryBean;
import com.yuque.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@RestControllerAdvice
public class CategoryController {
    @ExceptionHandler(Exception.class)
    public Result xx(Exception ex){
        ex.printStackTrace();// 输出异常
        Result pp = new Result();
        pp.setFlag(false);
        pp.setShuju("服务器异常，等会再试");
        return pp;
    }
@Autowired
private CategoryService categoryService;
    @RequestMapping("/cha")
    public Result xx(@RequestBody QueryBean queryBean){
        Page<category> fengye = categoryService.chaxun(queryBean);

        return new Result(true,fengye);
    }
  @RequestMapping("/shanchu/{uid}/{id}")
    public Result xx1(@PathVariable Integer uid,@PathVariable Integer id){
      categoryService.shanchu(uid,id);
      return new Result(true,null);
  }
  @RequestMapping("/selectByid")
    public  Result xx2(@RequestBody category category){
      int i = categoryService.selectByid(category);
      return new Result(true,i);
  }
    @RequestMapping("/chaid/{id}")
    public  Result xx3(@PathVariable Integer id){
        category chaid = categoryService.chaid(id);
        return new Result(true,chaid);
    }
    @RequestMapping("/chaxunsuoyou")
     public Result xx4(){
        List<category> chasuoyou = categoryService.chasuoyou();
        return new Result(true,chasuoyou);
    }
}
